package com.jbm.jbmsupplier.activity.searchconstrucation.presenter

import android.content.Context
import android.view.View
import com.jbm.enterapplication.InterfaceMa
import com.jbm.enterapplication.InterfaceMaArr
import com.jbm.jbmsupplier.activity.rxjavanet.ModeRxjavaNet
import com.jbm.jbmsupplier.activity.searchconstrucation.mode.Serch_Mode_Con
import com.jbm.jbmsupplier.activity.searchconstrucation.view.SerchContruiconInter
import com.jbm.jbmsupplier.view.DialogLoading
import com.jbm.jbmsupplier.view.DoubleButtonDialog
import com.jbm.onehome.iface.LoginEntity
import java.util.*

/**
 * Created by 家帮忙 on 2017/8/24.
 */
class Serch_Presenter_Con : Serch_Persenter_ConInter {
    override fun setAddFriendCon() {//添加好友
        dialogLoading = DialogLoading(context!!, "加载中.....", false)
        dialogLoading?.show()
        serchmodecon.setSerchAddFriend(userid!!, object : InterfaceMa<String> {

            override fun onSuccess(t: String, boolean: Boolean) {
                setDialogding()
                serchcontruicon!!.getAddSerchFriend()
                serchcontruicon?.finsh()
            }
            override fun setError(err: String, boolean: Boolean) {
                hint(err)
                setDialogding()
            }


        }
    )

    }

    private var userid: String? = null

    override fun setSerchPhot() {//搜索好友
        if (serchcontruicon!!.getPhot().length<11){
            serchcontruicon!!.getPhotErr().error = "手机号长度不对"
        }else if (serchcontruicon!!.getPhot().equals("")){
            serchcontruicon!!.getPhotErr().error= "手机号不能为空"
        }else{
            dialogLoading = DialogLoading(context!!, "加载中.....", false)
            dialogLoading?.show()
           serchmodecon.setSerchCont(serchcontruicon!!.getPhot(), object : InterfaceMaArr<String, LoginEntity> {
            override fun setError(err: String, boolean: Boolean) {
                setDialogding()
                hint(err)
            }

            override fun onSuccess(t: String, boolean: Boolean, arraylist: ArrayList<LoginEntity>) {
                userid=t
                setDialogding()
                serchcontruicon?.getSerchContMas()
                ModeRxjavaNet.getInstantMode().PicassIma(context!!,arraylist.get(0).logo, serchcontruicon?.getImageurl()!!)
                serchcontruicon?.getTexviewshig()?.text=arraylist.get(0).nickname
                serchcontruicon?.getTextViewPhot()?.text=   arraylist.get(0).accSecretEntity.mobile




            }


        }
)}
    }

    var serchmodecon = Serch_Mode_Con()
    var serchcontruicon: SerchContruiconInter? = null
    var  dialogLoading: DialogLoading?=null
    var context:Context?=null
    constructor(serchcontruicon: SerchContruiconInter?,context:Context?) {
        this.serchcontruicon = serchcontruicon
        this.context=context;
    }

    //一些提示的时候调用
    fun hint(name: String) {
        val dialog = DoubleButtonDialog(context, name)
        dialog.getokbtn().setOnClickListener(View.OnClickListener { dialog.dismiss() })
        dialog.setisVisibility()

    }
    fun setDialogding() {
        if (dialogLoading != null) {
            dialogLoading!!.dismiss()
        }
    }
}